package com.shipwe.loans.ui.presenter

import com.shipwe.loans.R
import com.shipwe.loans.http.ApiService
import com.shipwe.loans.http.IHttpCallback
import com.shipwe.loans.pro.ShipwePresenter
import com.shipwe.loans.ui.view.IUserAdviseView
import org.json.JSONObject

/**
 * Shipwe
 * @Author wwdeng
 * @CreateTime: 2024/11/27 16:26
 * @Annotation：意见反馈 Presenter 实现
 */
class UserAdvisePresenter(private val iView: IUserAdviseView): ShipwePresenter(iView) {

    private val typeTitleList = arrayListOf(R.string.feedback_type_suggest,R.string.feedback_type_bug,R.string.feedback_type_repayment_issues,R.string.feedback_type_other)
    private val typeValueList = arrayListOf("SUGGEST","BUG","PAYMENT","OTHER")

    //反馈类型列表
    private var typeList: ArrayList<JSONObject>? = null

    /**
     * 获取意见反馈类型
     */
    fun loadUserAdviseQuestionTypeListAction() {
        if (typeList == null){
            typeList = arrayListOf()
        }
        typeList!!.clear()
        for (i in 0..<typeTitleList.size){
            val obj = JSONObject()
            obj.put("title", typeTitleList[i])
            obj.put("value", typeValueList[i])
            obj.put("isSelect",false)
            typeList!!.add(obj)
        }
        iView.setUserAdviseQuestionTypeList(typeList!!)
    }

    /**
     * 提交反馈
     */
    fun submitUserAdviseAction(params: JSONObject){
        val httpUrl = ApiService.getHttpUrl()
        doHttpPostAction(httpUrl,params,object : IHttpCallback {
            override fun onRequestSuccess(data: JSONObject) {
                val msg = data.optString("msg")
                iView.showShipweToast(msg)
                iView.showUserAdviseSubmitSuccess()
            }

            override fun onRequestError(error: JSONObject) {
            }

            override fun onRequestFinish() {
                iView.dismissShipweLoading()
            }
        })
    }

    /**
     * 获取全部问题类型列表
     */
    fun getUserAdviseTypeList(): ArrayList<JSONObject>{
        return typeList!!
    }
}